package com.prabhakar.json;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import sun.org.mozilla.javascript.internal.json.JsonParser;

public class WrapIntoJson {

	public static String name ; 
	public static String phonenumber ;
	public static String address;
	public static String requestDate ;


	public static void main(String[] args) {

		SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
		requestDate = sdf.format(new Date());
	
		JSONArray jsonArray = new JSONArray();

		for(int i =1; i<4; i++){
			
			DemoBean demoBean = new DemoBean();
			demoBean.setName("prabhakar"+i);
			demoBean.setPhonenumber("748596500"+i+i);
			demoBean.setEmail("prabhakar"+i+"@mail.com");
			demoBean.setAddress("1st cross, 16th main, btm 2nd stage");
			demoBean.setRequestDate(requestDate);

			JSONObject jsonObj = toJsonObject(demoBean);
			String jsonValue = fromJsonObjectToString(jsonObj);
			jsonArray.add(jsonObj);
		}
	//	new ConsumeJson_Jackson().consumeJsonArray(jsonArray);
		new ConsumeJson().consumeJsonArray(jsonArray);
	}


	private static String fromJsonObjectToString(JSONObject jsonObj) {

		String stringvalue = "";
		if(!jsonObj.isEmpty()){
			stringvalue = jsonObj.toString();
		}
		System.out.println("json obj.to string  >> "+stringvalue);
		return stringvalue;
	}

	private static JSONObject toJsonObject(DemoBean demoBean_) {

		JSONObject js = new JSONObject();
		js.put("name", demoBean_.getName());
		js.put("phonenumber",demoBean_.getPhonenumber());
		js.put("requestDate",demoBean_.getRequestDate());
		js.put("email", demoBean_.getEmail());
		js.put("address", demoBean_.getAddress());
	
		return js;
	}
}




